﻿using System;
using System.IO;
using System.Reflection;
using System.Text;

namespace RuTrackerLibTests
{
    public static class ResourceReader
    {
        public static string ReadFileAsString(string name)
        {
            byte[] buffer = ReadFile(name);
            return Encoding.Default.GetString(buffer);
        }

        public static byte[] ReadFile(string name)
        {
            Assembly assembly = typeof (ResourceReader).Assembly;
            using (Stream stream = assembly.GetManifestResourceStream(assembly.GetName().Name + "." + name))
            {
                if (stream == null)
                    throw new ArgumentException(string.Format("Cannot load resource by name: {0}", name));

                byte[] buffer = new byte[stream.Length];
                stream.Read(buffer, 0, buffer.Length);
                return buffer;
            }
            
        }
    }
}
